package com.cd.works.domain;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCHelper {
	public static String url="jdbc:mysql://192.168.14.128:3306/clickdesigners";//jdbc:hsqldb:hsql://localhost/
	public static String uid="root";//SA
	public static String pwd="root";
//	public static String url="jdbc:mysql://localhost:3306/clickdesigners";//jdbc:hsqldb:hsql://localhost/
	static
	{
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
		}
		catch(ClassNotFoundException e)
		{
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection()
	{
		Connection con=null;
		try
		{
			System.out.println("Before Connection");
			con=DriverManager.getConnection(url,uid,pwd);
			System.out.println("After Connection");
			return con;
		}
		catch(SQLException e)
		{
			e.printStackTrace();
			return null;
		}
	}
	
	public static void close(ResultSet c) 
	{
		try
		{
			if(c!=null)
			{
				c.close();
			}
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
	
	public static void close(Connection c) 
	{
		try
		{
			if(c!=null)
			{
				c.close();
			}
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
	
	public static void close(Statement stmt) 
	{
		try
		{
			if(stmt!=null)
			{
				stmt.close();
			}
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
}
